#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <wait.h>
#include <sys/mman.h>
#include <sys/types.h>

#define MEMSIZE 1024

int main(int argc, char * argv[])
{
    char * ptr;
    pid_t pid;
    ptr = mmap(NULL, MEMSIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
    if(ptr == MAP_FAILED)
    {
        perror("mmap");
        exit(1);

    }

    pid = fork();
    if(pid < 0)
    {
        perror("fork");
        munmap(ptr, MEMSIZE);
        exit(1);
    }

    if(pid == 0)
    {
        //w
        strcpy(ptr, "hello");
        munmap(ptr, MEMSIZE);
        exit(0);
    }
    else
    {
        //r
        wait(NULL);
        puts(ptr);
        munmap(ptr, MEMSIZE);
        exit(0);
    }
}